package com.hw.hcit.feature;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.hw.hcit.R;
import com.hw.hcit.conf.Config;
import com.hw.hcit.conf.JCtrlCallback;
import com.hw.hcit.conf.JTestItem;

public class ProjectTest extends JTestItem implements OnItemClickListener 
{
	private String TAG = "ProjectTest";
	private ListView mlisListView;
	
	public ProjectTest() {
		super();
	}
	
	public ProjectTest(JCtrlCallback cb) {
		super(cb);
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
	{
		View rootView = inflater.inflate(R.layout.projects, container, false);
		
		mlisListView = (ListView) rootView.findViewById(R.id.test_list);
		
		mlisListView.setAdapter(new ArrayAdapter<String>(rootView.getContext(), android.R.layout.simple_list_item_1, getData()));
		
		mlisListView.setOnItemClickListener(this);
		
		return rootView;
	}

	@Override
	public boolean getResult() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public String getResultInfo() {
		// TODO Auto-generated method stub
		return ret;
	}

	@Override
	public void startTest() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void stopTest() {
		// TODO Auto-generated method stub
		
	}
	
	public void refresh()
	{
		
	}

	String ret = "";
	
	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
			long arg3) {
		// TODO Auto-generated method stub
		ret = String.valueOf(arg2);
		Log.d(TAG, "a1rg2="+arg2);
		Log.d(TAG, "a1rg3="+arg3);
		this.testFinish(true);
	}
	
	@Override
	public List<String> getData() {
		List<String> data = new ArrayList<String>();
		
		int c = Config.CURR_PROJECT.getSize();
		String s = "";
		for(int i=0;i<c;i++)
		{
			data.add(Config.CURR_PROJECT.getValue(i).getName());
		}
	         
	        return data;
	}
}
